package tech.eyao.hs60x.converts;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.util.CollectionUtils;

import tech.eyao.hs60x.common.CommonConstants;
import tech.eyao.hs60x.dto.AddressBookDTO;
import tech.eyao.hs60x.dto.WatchFriendDTO;
import tech.eyao.hs60x.enums.AccountType;
import tech.eyao.hs60x.model.domain.AccountRelationDO;

public class AccountRelationConvert {

	public static List<AddressBookDTO> convert(List<AccountRelationDO> accountRelationDOs) {
		
		if(!CollectionUtils.isEmpty(accountRelationDOs)) {
			return accountRelationDOs.stream().filter(a -> a.getRelationBusType() == AccountType.PHONE.getValue()).map(a -> {
				AddressBookDTO dto = new AddressBookDTO();
				dto.id = a.getId();
				dto.accountId = a.getRelationId();
				dto.isAdmin = a.getRoleCode() == null ? Boolean.FALSE : a.getRoleCode().equalsIgnoreCase(CommonConstants.ADMIN);
				dto.nickName = a.getRelationName();
				return dto;
			}).collect(Collectors.toList());
		}
		return null;
	}

	public static List<WatchFriendDTO> convertWatchFriendDTO(List<AccountRelationDO> accountRelationDOs) {
		if(!CollectionUtils.isEmpty(accountRelationDOs)) {
			return accountRelationDOs.stream().filter(a -> a.getRelationBusType() == AccountType.WATCH.getValue()).map(a -> {
				WatchFriendDTO dto = new WatchFriendDTO();
				dto.id = a.getId();
				dto.accountId = a.getRelationId();
				dto.nickName = a.getRelationName();
				return dto;
			}).collect(Collectors.toList());
		}
		return null;
	}
}
